package com.framework.service.impl;


import com.baomidou.mybatisplus.service.IService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.sys.SysBankLogoDao;
import com.framework.entity.sys.SysBank;
import com.framework.entity.sys.SysBankLogo;
import com.framework.exception.RRException;
import com.framework.service.BankService;
import com.framework.service.SysBankLogoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wq
 */
@Service("sysBankLogoService")
public class SysBankLogoServiceImpl extends ServiceImpl<SysBankLogoDao,SysBankLogo> implements SysBankLogoService {

    @Autowired
    private BankService bankService;

    @Override
    public SysBank setBankLogoId(SysBank bank) {

        Integer logoId = returnLogoIdByBankName(bank.getBankName());

        bank.setBankLogoId(logoId);
        bankService.updateById(bank);

        return bank;
    }

    @Override
    public Integer returnLogoIdByBankName(String bankName) {
        if(bankName==null){
            throw new RRException("9000","银行名称不能为空");
        }
        List<SysBankLogo> sysBankLogos = selectList(null);
        Integer logoId=null;
        for (SysBankLogo sysBankLogo : sysBankLogos) {
            if(bankName.contains(sysBankLogo.getBankName())){
                logoId=sysBankLogo.getLogoId();
            }
        }
        if(logoId==null){
            logoId=1;
        }
        return logoId;
    }
}
